package willevaluate.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.HashMap;

import common.BaseActivity;
import common.Constant;
import https.InterNetController;
import utils.UnitUtils;

/**
 * Created by Administrator on 2017/4/17.
 * 评估志愿列表
 */
@ContentView(R.layout.will_list)
public class WillList extends BaseActivity implements View.OnClickListener {
    @ViewInject(R.id.will_header_layout_count)
    private TextView will_header_layout_count;//头部分数
    @ViewInject(R.id.will_header_layout_rank)
    private TextView will_header_layout_rank;//头部排名
    @ViewInject(R.id.common_back)
    private ImageView common_back;
    @ViewInject(R.id.common_title)
    private TextView common_title;
    @ViewInject(R.id.will_list_item1)
    private RelativeLayout will_list_item1;
    @ViewInject(R.id.will_list_item2)
    private RelativeLayout will_list_item2;
    @ViewInject(R.id.will_list_item3)
    private RelativeLayout will_list_item3;
    @ViewInject(R.id.will_list_item1_tv)
    private TextView will_list_item1_tv;
    @ViewInject(R.id.will_list_item2_tv)
    private TextView will_list_item2_tv;
    @ViewInject(R.id.will_list_item3_tv)
    private TextView will_list_item3_tv;
    @ViewInject(R.id.will_list_item1_num_tv)
    private TextView will_list_item1_num_tv;
    @ViewInject(R.id.will_list_item2_num_tv)
    private TextView will_list_item2_num_tv;
    @ViewInject(R.id.will_list_item3_num_tv)
    private TextView will_list_item3_num_tv;

    private String count;
    private String rank;
    private String type;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case Constant.ERROR_CODE_SUCCESS://成功返回
                    try {
                        JSONObject jsonObject = new JSONObject(String.valueOf(msg.obj));
                        String low_count = jsonObject.getString("low_count");
                        String safe_count = jsonObject.getString("safe_count");
                        String high_count = jsonObject.getString("high_count");
                        will_list_item1_tv.setText("推荐冲刺高校 ");
                        will_list_item2_tv.setText("推荐稳妥高校 ");
                        will_list_item3_tv.setText("推荐保底高校 ");

                        will_list_item1_num_tv.setText(high_count);
                        will_list_item2_num_tv.setText(safe_count);
                        will_list_item3_num_tv.setText(low_count);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    break;
                default:
                    break;
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        count = getIntent().getStringExtra("count");
        type = getIntent().getStringExtra("type");
        rank = getIntent().getStringExtra("rank");
        initView();
        if (count != null) {
            will_header_layout_count.setText(count);
        } else {
            will_header_layout_count.setText("0");
        }
        if (rank != null) {
            will_header_layout_rank.setText(rank);
        } else {
            will_header_layout_rank.setText("0");
        }
        getDataFromInterNet();
    }

    private void initView() {
        common_title.setText("志愿评估概况");
        common_back.setOnClickListener(this);
        will_list_item1.setOnClickListener(this);
        will_list_item2.setOnClickListener(this);
        will_list_item3.setOnClickListener(this);
    }

    private void getDataFromInterNet() {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("count", count);
        hashMap.put("type", type);
        hashMap.put("rank", rank);
        new InterNetController(this, Constant.EVALUTESURVEY, handler, hashMap, 0);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.common_back:
                this.finish();
                break;
            case R.id.will_list_item1:
                //冲刺
                drump("冲刺");
                break;
            case R.id.will_list_item2:
                //稳妥
                drump("稳妥");
                break;
            case R.id.will_list_item3:
                //保底
                drump("保底");
                break;
            default:
                break;
        }
    }
    private void drump(String state){
        Intent i = new Intent(this,EvaluateOrder.class);
        i.putExtra("status",state);
        i.putExtra("count",count);
        i.putExtra("type",type);
        i.putExtra("rank",rank);
        startActivity(i);
    }
}
